package com.boot.bean;

import org.apache.commons.lang3.StringUtils;

import com.boot.util.JudgeUtil;
import com.geccocrawler.gecco.annotation.Attr;
import com.geccocrawler.gecco.annotation.Gecco;
import com.geccocrawler.gecco.annotation.Href;
import com.geccocrawler.gecco.annotation.HtmlField;
import com.geccocrawler.gecco.annotation.Image;
import com.geccocrawler.gecco.annotation.Request;
import com.geccocrawler.gecco.annotation.RequestParameter;
import com.geccocrawler.gecco.request.HttpRequest;
import com.geccocrawler.gecco.spider.HtmlBean;

import lombok.Data;

@Data
@Gecco(matchUrl = "http://m.99mm.me/{topic}/{imgNum}.html", pipelines = { "getPicDetail" })
public class llllPic implements HtmlBean {

	private static final long serialVersionUID = -377053120283382723L;

	@Request
	private HttpRequest request;

	@RequestParameter
	private String imgNum;

	@RequestParameter
	private String topic;

	@RequestParameter
	private String pageNum;

	@HtmlField(cssPath = "#picbox > a")
	private String biaoti;

	// 图片说明
	@Href(click = true)
	@HtmlField(cssPath = "#picbox > a")
	private String herf;

	// 图片
	@Image({ "data-lazy-img", "src" })
	@HtmlField(cssPath = "a > img")
	private String imgUrl;

	@Attr("width")
	@HtmlField(cssPath = "width")
	private String width;

	public void setBiaoti(String str) {
		if (!JudgeUtil.isPresent(str)) {
			return;
		}
		int alt = str.indexOf("alt");
		int one = str.indexOf("\"", alt);
		int two = str.indexOf("\"", one + 1);

		String substring = str.substring(one + 1, two);

		if (JudgeUtil.isPresent(pageNum)) {
			String removeStr = "(" + pageNum + ")";
			this.biaoti = StringUtils.replace(substring, removeStr, "");
		} else {
			this.biaoti = substring;
		}
	}

	public String getBiaoti() {
		return biaoti;
	}

	public PictureVo getPictureVo() {
		PictureVo pictureVo = new PictureVo();

		pictureVo.setBiaoti(biaoti);
		pictureVo.setHerf(herf);
		pictureVo.setImgUrl(imgUrl);
		pictureVo.setWidth(width);
		pictureVo.setTopic(topic);

		return pictureVo;
	}

}
